package com.cat.enumerate;

import java.util.HashMap;

/**
 *   @description https://leetcode.cn/problems/find-the-maximum-number-of-elements-in-subset/?envType=problem-list-v2&envId=enumeration
 *   @author 曲大人的喵
 *   @create 2025/9/21 19:39
 *   @since JDK17
 */

public class Solution13 {
    public int maximumLength(int[] nums) {
        HashMap<Long, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.merge((long)num, 1, Integer::sum);
        }
        Integer one = map.remove(1L);
        int ans = one != null ? one - 1 | 1 : 0;
        for (long x : map.keySet()) {
            int res = 0;
            for (; map.getOrDefault(x, 0) > 1; x *= x) {
                res += 2;
            }
            ans = Math.max(ans, res + (map.containsKey(x) ? 1 : -1));
        }

        return ans;
    }
}
